package com.youth.routercore

import androidx.fragment.app.Fragment

class RouterFragment : Fragment() {
//    companion object {
//        @OptIn(ExperimentalCoroutinesApi::class)
//        fun showAsFlow(fm: FragmentManager, intent: Intent): Flow<Result<Intent>> {
//            val fragment = RouterFragment()
//            return fm.showAsFlow(fragment) {
//                fragment.viewModel.callback = {
//                    trySend(Result.success(it))
//                    close()
//                }
//                fragment.launcher.launch(intent)
//            }
//        }
//    }
//
//    private val viewModel by lazy { ViewModelProvider(this).get(RouterViewModel::class.java) }
//    private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
//        val result = if (it.resultCode == Activity.RESULT_OK) {
//            it.data ?: Intent()
//        } else {
//            Intent()
//        }
//        viewModel.callback.invoke(result)
//
//        //clear current fragment
//        activity?.let { p ->
//            p.supportFragmentManager.remove(this)
//        }
//    }
//
//    class RouterViewModel : ViewModel() {
//        var callback: ((Intent) -> Unit) = {}
//    }
}
